using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace MTRC.ODMS.Web.SOM.AOActivityListing
{   /// <summary>
    /// Author:Nearly 
    /// Last Modify by zengshunbo 2008-12-26
    /// </summary>
    public partial class OutstandingActivitiesListing : BasePage_SOM
    {
        //string[] Arr = new string[1000];
        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140501";
            }
        }

        /*IsStatusOs Add by Dylan 20150617 for ISSUE U48  */
        protected bool IsStatusOs = false;
        /*IsStatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48  */
        protected bool IsStatusReturnedItemInOsEvent = false;

        #endregion

        #region  Page Load and UnLoad

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grdActivitiesListing.PageSize = this.GridViewPageDefaultSize();

                this.palEstimatedCompletion.Visible = false;
                InitializePage();
                btnStationStatus_ServerClick(null, EventArgs.Empty);
                SetLanguage();
                //added by Nathan 2015-08-15
                if (chkFreeTextSearch.Checked)
                {
                    TxtConditionOne.Enabled = true;
                    TxtConditionTwo.Enabled = true;
                    TxtConditionThree.Enabled = true;
                    rdoAnd.Enabled = true;
                    rdoOr.Enabled = true;

                }
                else
                {
                    TxtConditionOne.Enabled = false;
                    TxtConditionTwo.Enabled = false;
                    TxtConditionThree.Enabled = false;
                    rdoAnd.Enabled = false;
                    rdoOr.Enabled = false;
                    rdoAnd.Checked = true;
                    TxtConditionOne.Text = "";
                    TxtConditionTwo.Text = "";
                    TxtConditionThree.Text = "";
                    TextOne.Text = "";
                    TextTwo.Text = "";
                    TextThree.Text = "";
                }
                /*******************add by jack 20151202 for using session store enquiry condition satrt**********************/
                string isBack = Request.QueryString["isBack"];
                if (isBack == "1")
                {
                    this.ddlStation.SelectedValue = Session["Common_Station"].ToString();
                    this.dtbFromDate.Text = Session["Common_DateFrom"].ToString();
                    this.dtbToDate.Text = Session["Common_DateTo"].ToString();
                    this.SetCheckboxListValue(Session["Common_ShowList"].ToString(), this.chklShow);
                    this.SetCheckboxListValue(Session["OutstandingActivity_Category"].ToString(), this.cblWordCategory);
                    this.chkSearch.Checked = Convert.ToBoolean(Session["OutstandingActivity_Search"].ToString());
                    this.cbxReturnItemOs.Checked = Convert.ToBoolean(Session["OutstandingActivity_ReturnItemOs"].ToString());
                    Boolean boolFreeTextSearch = Convert.ToBoolean(Session["Common_FreeTextSearch"]);
                    this.chkFreeTextSearch.Checked = boolFreeTextSearch;
                    if (boolFreeTextSearch)
                    {
                        this.rdoAnd.Enabled = true;
                        this.rdoOr.Enabled = true;
                        this.TxtConditionOne.Enabled = true;
                        this.TxtConditionTwo.Enabled = true;
                        this.TxtConditionThree.Enabled = true;
                        this.TextOne.Text = Session["Common_ConditionOne"].ToString();
                        this.TextTwo.Text = Session["Common_ConditionTwo"].ToString();
                        this.TextThree.Text = Session["Common_ConditionThree"].ToString();
                    }
                    else
                    {
                        this.TxtConditionOne.ReadOnly = false;
                        this.TxtConditionTwo.ReadOnly = false;
                        this.TxtConditionThree.ReadOnly = false;
                    }
                    this.rdoAnd.Checked = Convert.ToBoolean(Session["Common_RdoAnd"]);
                    this.rdoOr.Checked = Convert.ToBoolean(Session["Common_RdoOr"]);
                    this.HiddenFieldIsBack.Value = "1";
                }
                /*******************add by jack 20151202 for using session store enquiry condition end**********************/
            }
        }
        private void InitializePage()
        {
            DateTime CurrentDateTimeTo = MTRC.ODMS.DAL.COM.Util.GetCurrentSystemTime();
            CurrentDateTimeTo = CurrentDateTimeTo.Date;
            this.dtbToDate.SetDateTime(CurrentDateTimeTo);

            string strDateRangel = DAL.CommonData.GetParameter("SOM_ActivityListingDateRange").Rows[0]["ParamNumeric"].ToString();
            if (strDateRangel.Length > 0)
            {
                DateTime CurrentDateTimeFrom = new DateTime();
                try
                {
                    CurrentDateTimeFrom = CurrentDateTimeTo.AddDays(-(int.Parse(strDateRangel)));
                }
                catch
                {
                    CurrentDateTimeFrom = CurrentDateTimeTo.AddDays(0);
                }
                this.dtbFromDate.SetDateTime(CurrentDateTimeFrom);
                //Begin liuwenjing    2015-09-30 issue:U224
                if (CurrentDateTimeFrom.ToString().Length > 0 && CurrentDateTimeTo.ToString().Length > 0)
                {
                    if (InvalidateInputDate(CurrentDateTimeFrom, CurrentDateTimeTo))
                    {
                        PAlert(this.GetMessage("COM_StartEndDate"));
                        return;
                    }
                }
                //End
            }

            string strInterval = DAL.CommonData.GetParameter("SOM_ActivityListingTimerSearch").Rows[0]["ParamNumeric"].ToString();
            if (strInterval.Length > 0)
            {
                try
                {
                    this.TimerRefresh.Interval = int.Parse(strInterval) * 1000;
                }
                catch
                {
                }
            }
            this.TimerRefresh.Enabled = false;

            if (DAL.Security.User.CanFunctionItemAccess("M140501_F1", this.ODMUser.UserProfileID, this.MenuID))//access all station.
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), this.ODMUser.StationID), true);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true);
            }
            else if (DAL.Security.User.CanFunctionItemAccess("M140501_F2", this.ODMUser.UserProfileID, this.MenuID))//Can Access other stations.
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.StationID), true);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true);
            }
            else
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.StationID), false);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.LocationID), false);
                this.ddlStation.Enabled = false;
            }

            //update by gordon 20151020 U247
            //this.FindByValueAndSelect(ddlStation, this.ODMUser.StationID.ToString());
            this.FindByValueAndSelect(ddlStation, this.ODMUser.LocationID.ToString());

            // add by dylan 20150826 for u167
            string AutoDefault = DAL.CommonData.GetParameter("SOM_ActivityListingAutoRefresh").Rows[0]["ParamCharVal"].ToString();
            if (AutoDefault.ToUpper().Equals("Y"))
            {
                chkSearch.Checked = true;
                this.TimerRefresh.Enabled = true;
            }
            else
            {
                chkSearch.Checked = false;
                this.TimerRefresh.Enabled = false;
            }
        }

        private void SetLanguage()
        {
            // remove by dylan 20150826 for u167
            //this.lblCurrentShift.Text = this.GetLabel("SOM_CurrentShift", true);
            //edit by hjh 20120519 for DataReader not close
            //remove by gordon 20150827 U167.6 | Duty SC Book On is no longer used
            //using (System.Data.SqlClient.SqlDataReader dr = MTRC.ODMS.DAL.SOM.Event.HandoverDa.GetCurrentHandoverStatus(this.LangCode, this.ODMUser.StationID))
            //{
            //    if (dr.Read())
            //    {
            //        // remove by dylan 20150826 for u167
            //        //this.lblCurStatusValue.Text = dr["Shift"].ToString();
            //        string strHandoverAgreeIndicator = dr["HandoverAgreeIndicator"].ToString();
            //        this.hdnShift.Value = strHandoverAgreeIndicator;
            //        // remove by dylan 20150826 for u167
            //        //if (strHandoverAgreeIndicator == "0")
            //        //{
            //        //    this.lblHandoverStatusValue.Text = this.GetLabel("SOM_ConfirmedNotOkay");
            //        //}
            //        //else if (strHandoverAgreeIndicator == "1")
            //        //{
            //        //    this.lblHandoverStatusValue.Text = this.GetLabel("SOM_ConfirmedOkay");
            //        //}
            //        //else if (strHandoverAgreeIndicator == "2")
            //        //{
            //        //    this.lblHandoverStatusValue.Text = this.GetLabel("SOM_Notconfirmed");
            //        //}

            //    }
            //    else
            //    {
            //        this.hdnShift.Value = "-1";  //have no status ,can not confirmed          
            //        //this.lblCurStatusValue.Text = this.GetLabel("SOM_NoHave");
            //        //this.lblHandoverStatusValue.Text = this.GetLabel("SOM_Notconfirmed");
            //    }
            //}
            //--------------------------------------------------------------------
            // remove by dylan 20150826 for u167
            //this.lblHandoverStatus.Text = this.GetLabel("SOM_CurrentHandoverStatus", true);

            // modified by dylan 20150703 for u63
            this.btnHandoverCheck.Value = this.GetLabel("SOM_HandoverCheckList");
            this.btnStationStatus.Value = this.GetLabel("SOM_StationStatus");
            //imgbtnReturned.ToolTip = this.GetLabel("SOM_StationStatus");
            this.btnRefresh.Text = this.GetLabel("COM_Refresh");
            // remove by dylan 20150826 for u167
            //this.lblStationStatus.Text = this.GetLabel("SOM_Station", true);
            this.lblDataTime.Text = this.GetLabel("SOM_DateTime", true);
            this.lblTotalWorkGoup.Text = this.GetLabel("SOM_TotalWorkGroups", true);
            //this.lblTotalWorker.Text = this.GetLabel("SOM_TotalWorkers", true); //huangyao 20081126
            this.lblStation.Text = GetLabel("SOM_Station", true); //LiangZehong on 2008-12-18
            this.lblEstimatedCompletion.Text = GetLabel("SOM_EstimateCompletionDateTime", true);
            this.lblFrom.Text = this.GetLabel("COM_From", true);
            this.lblTo.Text = this.GetLabel("COM_To", true);
            this.lblShow.Text = this.GetLabel("COM_Show", true);
            BindListControl(chklShow, "EventStatusID", "Description", DAL.SOM.CodeSetup.CDEventStatus.GetActive(this.LangCode), false);
            int intShowCount = this.chklShow.Items.Count;
            for (int i = 0; i < intShowCount; i++)
            {
                if (this.chklShow.Items[i].Value == "1")
                {
                    this.chklShow.Items[i].Selected = true;
                }
            }
            if (intShowCount > 0)
            {
                this.chklShow.Items.Insert(intShowCount - 1, this.GetLabel("SOM_Handover"));
                this.chklShow.Items[intShowCount - 1].Selected = true;
            }
            else
            {
                this.chklShow.Items.Insert(0, this.GetLabel("SOM_Handover"));
                this.chklShow.Items[0].Selected = true;
            }

            //this.lblWordCategory.Text = this.GetLabel("SOM_EventCategory", true);
            BindListControl(cblWordCategory, "EventTypeID", "Description", DAL.SOM.CodeSetup.CDEventType.GetWorkCategoryExceptSClogon(this.LangCode), false);
            for (int i = 0; i < this.cblWordCategory.Items.Count; i++)
            {
                this.cblWordCategory.Items[i].Selected = true;
            }
            this.chkFreeTextSearch.Text = this.GetLabel("COM_FreeTextSearch", true);
            this.rdoAnd.Text = this.GetLabel("SOM_And");
            this.rdoOr.Text = this.GetLabel("SOM_Or");
            this.btnSearch.Value = this.GetLabel("COM_Search");
            this.chkSearch.Text = this.GetLabel("SOM_AutoRefresh");
            this.btnExporttoExcel.Value = this.GetLabel("COM_Export");
            // remove by dylan 20150826 for u167  
            //this.btnChangeToNormal.Value = this.GetLabel("SOM_CancelHightLight");
            lblAdmissionRegistry.Text = this.GetLabel("SOM_AdmissionRegistry");
            lblGenEvent.Text = this.GetLabel("SOM_GenEvent");
            lblFireProtection.Text = this.GetLabel("SOM_FireProtection");
            lblAssetLoanSectionName.Text = this.GetLabel("SOM_AssetLoanSectionName");
            this.lblWordCategory.Text = this.GetLabel("SOM_WordCategory", true); //Add by LiangZehong on 2008-12-18
            this.cbxReturnItemOs.Text = this.GetLabel("SOM_ReturnedItemOfOSEvent", false);// add by dylan 20150723 for u53
            if (Request.QueryString["isBack"] != null && Request.QueryString["isBack"].Trim() != string.Empty && Convert.ToInt32(Request.QueryString["isBack"].ToString()) > 0)
            {

            }
            else
            {
                BindData(true);
            }
        }

        private void ChangeLanguage_Click(object sender, System.EventArgs e)
        {
            if (IsPostBack) //added by huangyao 20090120
            {
                //BindData(true);
                InitializePage();
                this.btnStationStatus_ServerClick(null, EventArgs.Empty); //huangyao 20090305
            }
            SetLanguage();
        }

        #endregion

        #region Click Event

        //protected void imgbtnReturned_Click(object sender, ImageClickEventArgs e)
        //{
        //    //throw new Exception("The method or operation is not implemented.");
        //    this.btnStationStatus_ServerClick(null, EventArgs.Empty);
        //}

        private void btnStationStatus_ServerClick(object sender, EventArgs e)
        {
            this.lblDataTimeValue.Text = this.FormatDateTime(MTRC.ODMS.DAL.COM.Util.GetCurrentSystemTime(), true, true);
            //edit by hjh 20120519 for DataReader not close
            //update by gordon 20151020 U247
            //using (System.Data.SqlClient.SqlDataReader dr = MTRC.ODMS.BLL.SOM.Event.StationActivitiesListing.GetStationStatus(this.LangCode, this.ODMUser.StationID))
            using (System.Data.SqlClient.SqlDataReader dr = MTRC.ODMS.BLL.SOM.Event.StationActivitiesListing.GetStationStatus(this.LangCode, this.ODMUser.LocationID))
            {
                if (dr.Read())
                {
                    // remove by dylan 20150826 for u167
                    //this.lblStationStatusValue.Text = dr["Status"].ToString();
                    this.lblTotalWorkGoupValue.Text = dr["TotalWorkGoup"].ToString() + "/" + dr["TotalWorker"].ToString();
                    //this.lblTotalWorkerValue.Text = dr["TotalWorker"].ToString(); //huangyao 20081126
                }
            }
        }

        protected void BFSearc_ServerClick(object sender, EventArgs e)
        {
            try
            {
                //added by Nathan 2015-08-15
                if (chkFreeTextSearch.Checked)
                {
                    JMText();
                }
                if (dtbFromDate.Text.Trim().Length > 0 && dtbToDate.Text.Trim().Length > 0)
                {
                    if (InvalidateInputDate(this.dtbFromDate.GetDateTime(), this.dtbToDate.GetDateTime()))
                    {
                        PAlert(this.GetMessage("COM_StartEndDate"));
                        return;
                    }
                }

                if (this.chkEstimatedCompletion.Checked && this.dtbEstimatedCompletion.GetDateTime() == DateTime.MinValue)
                {
                    Alert(this.GetMessage("SOM_ErrNeedEstimatedCompletionTime"));
                    return;
                }
                BindData(true);
            }
            finally
            {
                //add by gordon 20150812 | For Search Wait Cursor
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", "showWait('');", true);
            }
        }
        protected void btnSearch_ServerClick(object sender, EventArgs e)
        {
            try
            {
                //added by Nathan 2015-08-15
                if (chkFreeTextSearch.Checked)
                {
                    TxtJM();
                }
                if (dtbFromDate.Text.Trim().Length > 0 && dtbToDate.Text.Trim().Length > 0)
                {
                    if (InvalidateInputDate(this.dtbFromDate.GetDateTime(), this.dtbToDate.GetDateTime()))
                    {
                        this.PAlert(this.GetMessage("COM_StartEndDate"));
                        return;
                    }
                }

                if (this.chkEstimatedCompletion.Checked && this.dtbEstimatedCompletion.GetDateTime() == DateTime.MinValue)
                {
                    Alert(this.GetMessage("SOM_ErrNeedEstimatedCompletionTime"));
                    return;
                }
                BindData(true);
            }
            finally
            {
                //add by gordon 20150812 | For Search Wait Cursor
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", "showWait('');", true);
            }



        }

        /// remove by dylan 20150826 for u167
        /// Before icon to click on the link But now do not have this function
        /// So don't need this function button
        //private void btnChangeToNormal_ServerClick(object sender, EventArgs e)
        //{
        //    if (this.hdnCancelHightLight.Value.Length > 1)
        //    {
        //        int intResult = MTRC.ODMS.DAL.SOM.Event.StationEventDa.CancelHightLight(hdnCancelHightLight.Value, this.ODMUser.ID);
        //        if (intResult >= 0)
        //        {
        //            // edit by Kingkong Chan 20140730 for Code Merge (Changeset: 25619, 25747, 26099)
        //            Alert(GetMessage("SaveOK"));//update by hujianhua 20100915 for tfs issue 1953
        //            BindData(false);
        //        }
        //        else
        //        {
        //            Alert(GetMessage("SOM_UpdatedError"));//update by hujianhua 20100915 for tfs issue 1953
        //        }
        //    }
        //}

        private void btnExporttoExcel_ServerClick(object sender, EventArgs e)
        {
            //edit by hjh 20120516 for issue 1531
            //if (this.hdnCacheDataReturnInt.Value != "0")
            //{
            if (dtbFromDate.Text.Trim().Length > 0 && dtbToDate.Text.Trim().Length > 0)
            {
                if (InvalidateInputDate(this.dtbFromDate.GetDateTime(), this.dtbToDate.GetDateTime()))
                {
                    PAlert(this.GetMessage("COM_StartEndDate"));
                    return;
                }
            }

            if (this.chkEstimatedCompletion.Checked && this.dtbEstimatedCompletion.GetDateTime() == DateTime.MinValue)
            {
                Alert(this.GetMessage("SOM_ErrNeedEstimatedCompletionTime"));
                return;
            }

            //DataSet dsReturn = BLL.SOM.TempData.GetCacheData(int.Parse(this.hdnCacheDataReturnInt.Value));
            DataSet dsReturn = this.getData();
            object limitExpCount = DAL.CommonData.GetNumVal("SOM_OutstandingExportMAXControl");
            if (dsReturn == null)
            {
                /********edit by jack 20151130 for u253 Processing application errors and exceptions start****/
                //return;
                string errorMessage = string.Format(GetMessage("SOM_OutstandingActivitiesListingException", this.LangCode), GetLineNum());
                /********edit by jack 20151130 for u253 Processing application errors and exceptions end****/
                Application_Error(errorMessage, "OutstandingActivitiesListing.aspx.cs");
            }
            else if (limitExpCount != null && dsReturn.Tables[0].Rows.Count > int.Parse(limitExpCount.ToString()))//edit by hjh 20120516 for issue 1531
            {
                Alert(string.Format(this.GetMessage("SOM_ExportLimitControl"), int.Parse(limitExpCount.ToString())));
                return;
            }

            DataSet dsCopyReturn = new DataSet();
            dsCopyReturn = dsReturn.Copy();
            dsReturn.Dispose();
            dsReturn = null;
            DataTable dtSearchResult = new DataTable();
            dtSearchResult = dsCopyReturn.Tables[0];
            dtSearchResult.Columns.Remove("EventStatusID");
            dtSearchResult.Columns.Remove("ParentStationEventID");
            dtSearchResult.Columns.Remove("ParentEventStatus"); //add by zengshunbo 2008-12-24

            dtSearchResult.Columns["EventNo"].ColumnName = this.GetLabel("SOM_EventNo");
            dtSearchResult.Columns["EventTime"].ColumnName = this.GetLabel("SOM_EventTime");
            dtSearchResult.Columns["EstimatedWrkHour"].ColumnName = this.GetLabel("SOM_EstimateCompletionDateTime");
            dtSearchResult.Columns["Description"].ColumnName = this.GetLabel("COM_Description");
            dtSearchResult.Columns["FlagHandover"].ColumnName = this.GetLabel("SOM_Handover");
            dtSearchResult.Columns["HandoverNote"].ColumnName = this.GetLabel("SOM_HandoverNote");
            //dtSearchResult.Columns[8].ColumnName = this.GetLabel("SOM_HighLight");
            dtSearchResult.Columns["EventStatusDesc"].ColumnName = this.GetLabel("COM_Status");
            dtSearchResult.Columns["EventType"].ColumnName = this.LangCode == "1" ? this.GetLabel("SOM_EventCategory") : this.GetLabel("SOM_EventCategory") + "1";//modify by zengshunbo 2008-12-24
            dtSearchResult.Columns["ParentEventNo"].ColumnName = this.GetLabel("SOM_AdmissionRegistryNo");
            dtSearchResult.Columns["ParentEventStatusID"].ColumnName = this.GetLabel("SOM_AdmissionRegistryStatus");
            dtSearchResult.Columns["StaffName"].ColumnName = this.GetLabel("COM_StaffName");
            dtSearchResult.Columns["DepartmentCompany"].ColumnName = this.GetLabel("SOM_DepartmentCompany");
            dtSearchResult.Columns["Tel"].ColumnName = this.GetLabel("COM_ContactNo");

            dtSearchResult.Columns["EventNoOfWorkers"].ColumnName = this.GetLabel("SOM_NoOfWorkers");
            dtSearchResult.Columns["JobLocation"].ColumnName = this.GetLabel("SOM_JobLocation");
            dtSearchResult.Columns["TNNo"].ColumnName = this.GetLabel("SOM_TNNumber");
            dtSearchResult.Columns["JobProtection"].ColumnName = this.GetLabel("SOM_JobProtection");
            dtSearchResult.Columns["ECSStatus1"].ColumnName = this.GetLabel("SOM_ESC1");
            dtSearchResult.Columns["ECSStatus2"].ColumnName = this.GetLabel("SOM_ESC2");
            dtSearchResult.Columns["ECSStatus3"].ColumnName = this.GetLabel("SOM_ESC3");

            dtSearchResult.Columns["FireSystem"].ColumnName = this.GetLabel("SOM_FireProtectionSystem");
            dtSearchResult.Columns["FireLinkStatus"].ColumnName = this.GetLabel("SOM_FireLinkStatus");
            dtSearchResult.Columns["IsolatedGrp"].ColumnName = this.GetLabel("SOM_FireZoneGroupLoopBeingIsolated");

            dtSearchResult.Columns["WorkCategory"].ColumnName = this.GetLabel("SOM_WorkCategory");
            dtSearchResult.Columns["WorkSubCategory"].ColumnName = this.GetLabel("SOM_WorkSubCategory");
            //dtSearchResult.Columns[28].ColumnName = this.GetLabel("SOM_RemindTime");//delete by gordon 20150721 U138
            // add by dylan 20150728 for u133
            dtSearchResult.Columns["Remark"].ColumnName = this.GetLabel("COM_Remark");
            dtSearchResult.Columns.Add();//HighLight
            dtSearchResult.Columns.Add();//AssetTypeDesc
            dtSearchResult.Columns.Add();//AssetItemDesc
            dtSearchResult.Columns.Add();//NumOfLoanItem
            dtSearchResult.Columns.Add();//NumOfReturnItem
            DataTable dt = new DataTable();
            /******************* modifidy by dylan 20150727 for u133 start**********************************/
            for (int i = 0; i < dtSearchResult.Rows.Count; i++)
            {
                // add by dylan 20150727 for u133 
                // edit by dylan 20150813 for issue 
                if (dtSearchResult.Rows[i]["EstimatedHour"].ToString() == "0.00" || dtSearchResult.Rows[i]["EstimatedHour"].ToString() == "")
                {
                    dtSearchResult.Rows[i][this.GetLabel("SOM_EstimateCompletionDateTime")] = DBNull.Value;
                }
                if (dtSearchResult.Rows[i]["HighLight"].ToString() == "1")
                {
                    dtSearchResult.Rows[i][30] = GetLabel("SOM_HighLightYellow");
                }
                else if (dtSearchResult.Rows[i]["HighLight"].ToString() == "2")
                {
                    dtSearchResult.Rows[i][30] = GetLabel("SOM_HighLightRed");
                }
                else
                {
                    dtSearchResult.Rows[i][30] = GetLabel("SOM_HighLightNormal");
                }

                if (dtSearchResult.Rows[i][1].ToString() == "2")
                {
                    /*IsStatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48  */
                    dt = MTRC.ODMS.BLL.SOM.Event.StationEventAssetLoan.GetByStationEventID(Convert.ToInt32(dtSearchResult.Rows[i][0].ToString()), IsStatusReturnedItemInOsEvent, IsStatusOs);
                    if (dt.Rows.Count > 0)
                    {
                        string arrAssetTypeDesc = "";
                        string arrAssetItemDesc = "";
                        string arrNumOfLoanItem = "";
                        string arrNumOfReturnItem = "";
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            arrAssetTypeDesc += "/" + dt.Rows[j]["AssetTypeDesc"].ToString();
                            arrAssetItemDesc += "/" + dt.Rows[j]["AssetItemDesc"].ToString();
                            arrNumOfLoanItem += "/" + dt.Rows[j]["NumOfLoanItem"].ToString();
                            arrNumOfReturnItem += "/" + dt.Rows[j]["NumOfReturnItem"].ToString();
                        }
                        dtSearchResult.Rows[i][31] = arrAssetTypeDesc.Substring(1);
                        dtSearchResult.Rows[i][32] = arrAssetItemDesc.Substring(1);
                        dtSearchResult.Rows[i][33] = arrNumOfLoanItem.Substring(1);
                        dtSearchResult.Rows[i][34] = arrNumOfReturnItem.Substring(1);
                    }

                }

            }
            dt.Dispose();
            dt = null;
            dtSearchResult.Columns.Remove("HighLight");
            dtSearchResult.Columns.Remove("EstimatedHour");
            dtSearchResult.Columns[28].ColumnName = this.GetLabel("SOM_HighLight"); //add by zengshunbo 2008-12-24
            dtSearchResult.Columns[29].ColumnName = this.GetLabel("COM_Category");
            dtSearchResult.Columns[30].ColumnName = this.LangCode == "1" ? this.GetLabel("SOM_Item") : this.GetLabel("SOM_Item") + "1";//add by zengshunbo 2008-12-24
            dtSearchResult.Columns[31].ColumnName = this.GetLabel("SOM_LoanQuantity");
            dtSearchResult.Columns[32].ColumnName = this.GetLabel("SOM_ReturnQuantity");
            // add by dylan 20150727 for u133
            dtSearchResult.Columns[this.GetLabel("COM_Remark")].SetOrdinal(32);
            dtSearchResult.Columns.Remove("StationEventID");
            dtSearchResult.Columns.Remove("EventTypeID");
            /******************* modifidy by dylan 20150727 for u133 end**********************************/

            /******************* add by dylan 20150727 for u133 start**********************************/
            dtSearchResult.Columns[this.GetLabel("COM_Remark")].SetOrdinal(30);
            //Common.ExportExcel_showHHMM(dsCopyReturn, Context, "OutstandingActivitiesListing.xls");
            //string templateFile = Server.MapPath("~") + string.Format(@"\Template\MTRC\OutstandingActivitiesListing Template.xlsx");
            string templateFilePath = APJ.Util.Utility.GetAppSetting("SOM_ExportExcelTemplatePath");
            if (templateFilePath.LastIndexOf("\\") != templateFilePath.Length - 1)
                templateFilePath += "\\";
            string templateFile = templateFilePath + string.Format("OutstandingActivitiesListing Template.xlsx");//add by jack 20160127 ISU22 fixed for same export file name
            //string exportFile = Server.MapPath("~") + string.Format(@"\Template\MTRC\OutstandingActivitiesListing.xlsx");
            string ExcelDownloadFilePath = APJ.Util.Utility.GetAppSetting("SOM_ExportExcelTempFilePath");
            if (ExcelDownloadFilePath.LastIndexOf("\\") != ExcelDownloadFilePath.Length - 1)
                ExcelDownloadFilePath += "\\";
            string exportFile = ExcelDownloadFilePath + string.Format("OutstandingActivitiesListing" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");//add by jack 20160127 ISU22 fixed for same export file name
            //update by gordon 20150910
            //CreateExcelFile.ExportExcelWithTemplate(dtSearchResult, templateFile, exportFile, Response);
            CreateExcelFile.ExportExcelWithTemplate(dtSearchResult, templateFile, exportFile, Response, Page);
            /******************* add by dylan 20150727 for u133 end**********************************/

            dtSearchResult.Dispose();
            dtSearchResult = null;
            dsCopyReturn.Dispose();
            dsCopyReturn = null;
            //}
        }

        #endregion

        #region Data Grid Bind

        private void BindData(bool blBindCount)
        {
            /* Comment by jack 20150824 for u70 */
            if (DAL.Security.User.CanFunctionItemAccess("M140501_F1", this.ODMUser.UserProfileID, this.MenuID))//access all station.
            {

            }
            else if (DAL.Security.User.CanFunctionItemAccess("M140501_F2", this.ODMUser.UserProfileID, this.MenuID))//Can Access other stations.
            {

            }
            else
            {
                if (!IsValidStation(this.ODMUser.LocationID))
                {
                    this.PAlert(this.GetMessage("SOM_NotValidStation"));
                    this.ddlStation.Items.Clear();
                    DataTable dtNull = new DataTable();
                    this.grdActivitiesListing.DataSource = dtNull.DefaultView;
                    this.grdActivitiesListing.GetLabelFunction = new APJ.Web.UI.WebControls.GetLabel(this.GetLabel);
                    this.grdActivitiesListing.DataBind();
                    dtNull.Dispose();
                    return;
                }

            }
            /************************************/

            //edit by hjh 20120516 for issue 1531
            DataSet dsSearchResult = this.getData();
            //this.hdnCacheDataReturnInt.Value = BLL.SOM.TempData.CacheDataSet(dsSearchResult, this.ODMUser.ID, this.ODMUser.Domain.ToString()).ToString();
            DataTable dtSearchResult = new DataTable();
            dtSearchResult = dsSearchResult.Tables[0];
            hdnCancelHightLight.Value = null;
            if (dtSearchResult.Rows.Count > 0)
            {
                // this.btnExporttoExcel.Disabled = false;
                // remove by dylan 20150826 for u167 
                //this.btnChangeToNormal.Disabled = false;

                //Remove by jack 20151021 for SOMS Perfomance 4.3
                //for (int i = 0; i < dtSearchResult.Rows.Count; i++)
                //{
                //    this.hdnCancelHightLight.Value += "," + dtSearchResult.Rows[i]["StationEventID"].ToString().Trim();
                //}
            }
            else
            {
                // remove by dylan 20150826 for u167 
                //this.btnChangeToNormal.Disabled = true;
                // this.btnExporttoExcel.Disabled = true;
            }
            this.grdActivitiesListing.GetLabelFunction = new APJ.Web.UI.WebControls.GetLabel(this.GetLabel);
            this.grdActivitiesListing.DataSource = dtSearchResult.DefaultView;
            this.grdActivitiesListing.DataBind();



            if (blBindCount)
            {
                lblAdmissionRegistryValue.Text = " : " + dtSearchResult.Select("EventTypeID=1").Length.ToString();
                dtSearchResult = dsSearchResult.Tables[0];
                lblGenEventValue.Text = " : " + dtSearchResult.Select("EventTypeID=4").Length.ToString();
                dtSearchResult = dsSearchResult.Tables[0];
                lblFireProtectionValue.Text = " : " + dtSearchResult.Select("EventTypeID=3").Length.ToString();
                dtSearchResult = dsSearchResult.Tables[0];
                lblAssetLoanSectionNameValue.Text = " : " + dtSearchResult.Select("EventTypeID=2").Length.ToString();
            }

            dtSearchResult.Dispose();
            dtSearchResult = null;
            dsSearchResult.Dispose();
            dsSearchResult = null;
        }

        private void grdActivitiesListing_NeedDataBind()
        {
            BindData(false);
        }

        protected void grdActivitiesListing_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
            {
                //string strEventTime = this.FormatDateTime(grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventTime"], true);
                string strEventTime = this.FormatDateTime_AddBR(grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventTime"]);

                //HighLight
                string strHighLightIcon = "";
                string strHighLight = grdActivitiesListing.DataKeys[e.Row.RowIndex]["HighLight"].ToString();
                string strStationEventID = grdActivitiesListing.DataKeys[e.Row.RowIndex]["StationEventID"].ToString();
                //update by benson 2015.07.22  U137 begin
                if (strHighLight == "1")
                {
                    //strHighLightIcon = "<input src=\"../../Images/SOM/HighLight_Yellow.gif\" onclick=\"HTML_ChangeHightLight( '" + strStationEventID + "^" + strHighLight + "');\" type=\"image\" title=" + GetLabel("SOM_HighLightYellow") + "></input>";
                    strHighLightIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/HighLight_Yellow.gif' style='border-width:0px' title='" + GetLabel("SOM_HighLightYellow") + "'/>";
                }
                else if (strHighLight == "2")
                {
                    //strHighLightIcon = "<input src=\"../../Images/SOM/HighLight_Red.gif\" onclick=\"HTML_ChangeHightLight( '" + strStationEventID + "^" + strHighLight + "');\" type=\"image\" title=" + GetLabel("SOM_HighLightRed") + "></input>";
                    strHighLightIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/HighLight_Red.gif' style='border-width:0px' title='" + GetLabel("SOM_HighLightRed") + "'/>";
                }
                else
                {
                    //strHighLightIcon = "<input src=\"../../Images/SOM/HighLight_Normal.gif\" onclick=\"HTML_ChangeHightLight( '" + strStationEventID + "^" + strHighLight + "');\" type=\"image\" title=" + GetLabel("SOM_HighLightNormal") + "></input>";
                    strHighLightIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/HighLight_Normal.gif' style='border-width:0px' title='" + GetLabel("SOM_HighLightNormal") + "'/>";
                }
                //update by benson 2015.07.22  U137 end
                //FlagHandover
                string strFlagHandoverIcon = "";
                string strFlagHandover = grdActivitiesListing.DataKeys[e.Row.RowIndex]["FlagHandover"].ToString().ToUpper();
                string strHandoverNote = grdActivitiesListing.DataKeys[e.Row.RowIndex]["HandoverNote"].ToString();
                string strEventStatusID = grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventStatusID"].ToString();
                if (strFlagHandover == "TRUE")
                {
                    strFlagHandoverIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/EventHandOver.gif' style='border-width:0px' title='" + strHandoverNote + "'/>";
                }
                // edit by dylan 20150706
                if (strFlagHandover == "FALSE" && !string.IsNullOrEmpty(strHandoverNote))
                {
                    strFlagHandoverIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/EventHandOverDone.jpg' style='border-width:0px' title='" + strHandoverNote + "'/>";
                }
                string strEventURL = "";
                string strDifferentByStatusID = "";

                string strEventTypeID = grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventTypeID"].ToString();
                string strEstimatedWrkHour = this.FormatDateTime(grdActivitiesListing.DataKeys[e.Row.RowIndex]["EstimatedWrkHour"], true);
                //string strEventRemindTime = this.FormatDateTime(grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventRemindTime"], true);
                //update by gordon 20150818
                //string strDifferentTime = "<table><tr><td>" + GetLabel("SOM_EstimateCompletionDateTime", true) + "</td><td>" + strEstimatedWrkHour + "</td></tr></table>";
                string strDifferentTime = "<table><tr><td>" + GetLabel("SOM_EstimateCompletionDateTime", true) + "</td><td>" + (strEstimatedWrkHour == strEventTime.Replace("<br/>", " ") ? "" : strEstimatedWrkHour) + "</td></tr></table>";
                if (strEventTypeID == "1")
                {
                    strEventURL = "AdmissionRegistry/AdmissionRegistryEntry.aspx?PageID=OutstandingActivitiesListing&";
                    string strEventNoOfWorkers = grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventNoOfWorkers"].ToString();
                    string strJobLocation = grdActivitiesListing.DataKeys[e.Row.RowIndex]["JobLocation"].ToString();
                    string strTNNo = grdActivitiesListing.DataKeys[e.Row.RowIndex]["TNNo"].ToString();
                    string strJobProtection = grdActivitiesListing.DataKeys[e.Row.RowIndex]["JobProtection"].ToString();
                    string strECSStatus1 = grdActivitiesListing.DataKeys[e.Row.RowIndex]["ECSStatus1"].ToString();
                    string strECSStatus2 = grdActivitiesListing.DataKeys[e.Row.RowIndex]["ECSStatus2"].ToString();
                    string strECSStatus3 = grdActivitiesListing.DataKeys[e.Row.RowIndex]["ECSStatus3"].ToString();

                    strDifferentByStatusID += "<table><tr><td>" + GetLabel("SOM_NoOfWorkers", true) + "</td><td>" + strEventNoOfWorkers + "</td></tr>";
                    strDifferentByStatusID += "<tr><td>" + GetLabel("SOM_JobLocation", true) + "</td><td>" + strJobLocation + "</td></tr>";
                    strDifferentByStatusID += "<tr><td>" + GetLabel("SOM_TNNumber", true) + "</td><td>" + strTNNo + "</td></tr>";
                    strDifferentByStatusID += "<tr><td>" + GetLabel("SOM_JobProtection", true) + "</td><td>" + strJobProtection + "</td></tr>";
                    //strDifferentByStatusID += "<tr><td colspan='2'><table cellpadding='0' cellspacing='0' width='100%'><tr><td style='width: 33%;'>" + GetLabel("SOM_ESC1", true) + "</td><td style='width: 33%;'>" + GetLabel("SOM_ESC2", true) + "</td><td>" + GetLabel("SOM_ESC3", true) + "</td></tr><tr><td>==========</td><td>==========</td><td>==========</td></tr>";
                    //strDifferentByStatusID += "<tr><td>" + strECSStatus1 + "</td><td>" + strECSStatus2 + "</td><td>" + strECSStatus3 + "</td></tr></table></td></tr>";
                    strDifferentByStatusID += "</table>";

                    strDifferentByStatusID += string.Format("<table border='0' cellspacing='5' style='margin:0;width:50%'><tr><td class='dashedline'>{0}</td><td class='dashedline'>{1}</td><td class='dashedline'>{2}</td></tr>", GetLabel("SOM_ESC1", true), GetLabel("SOM_ESC2", true), GetLabel("SOM_ESC3", true));
                    strDifferentByStatusID += "<tr><td>" + strECSStatus1 + "</td><td>" + strECSStatus2 + "</td><td>" + strECSStatus3 + "</td></tr></table>";
                }
                else if (strEventTypeID == "2")
                {
                    strEventURL = "AssetLoan/AssetLoanEntry.aspx?PageID=OutstandingActivitiesListing&";
                    /*IsStatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48  */
                    DataTable dt = MTRC.ODMS.BLL.SOM.Event.StationEventAssetLoan.GetByStationEventID(Convert.ToInt32(strStationEventID), IsStatusReturnedItemInOsEvent, IsStatusOs);
                    if (dt.Rows.Count > 0)
                    {
                        //strDifferentByStatusID += "<table><tr><td colspan='2'><table cellpadding='0' cellspacing='0' width='100%'><tr><td style='width: 20%;'>" + GetLabel("COM_Category") + "</td><td>" + GetLabel("SOM_Item") + "</td><td style='width: 20%;'>" + GetLabel("SOM_LoanQuantity") + "</td><td style='width: 25%;'>" + GetLabel("SOM_ReturnQuantity") + "</td></tr><tr><td>======</td><td>=============</td><td>======</td><td>======</td></tr>";
                        strDifferentByStatusID += "<table cellspacing='5'border='0' width='70%'><tr><td class='dashedline'>" + GetLabel("SOM_AssetItem") + "</td><td style='width: 90px' class='dashedline'>" + GetLabel("SOM_LoanQuantity") + "</td><td style='width: 90px;' class='dashedline'>" + GetLabel("SOM_ReturnQuantity") + "</td></tr>";
                        //string strAssetTypeDesc = "";
                        string strAssetItemDesc = "";
                        string strNumOfLoanItem = "";
                        string strNumOfReturnItem = "";
                        //string arrAssetTypeDesc = "";
                        //string arrAssetItemDesc = "";
                        //string arrNumOfLoanItem = "";
                        //string arrNumOfReturnItem = "";
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            //strAssetTypeDesc = dt.Rows[i]["AssetTypeDesc"].ToString();
                            strAssetItemDesc = dt.Rows[i]["AssetItemDesc"].ToString();
                            strNumOfLoanItem = dt.Rows[i]["NumOfLoanItem"].ToString();
                            strNumOfReturnItem = dt.Rows[i]["NumOfReturnItem"].ToString();
                            //strDifferentByStatusID += "<tr><td>" + strAssetTypeDesc + "</td><td>" + strAssetItemDesc + "</td><td>" + strNumOfLoanItem + "</td><td>" + strNumOfReturnItem + "</td></tr>";
                            strDifferentByStatusID += "<tr><td>" + strAssetItemDesc + "</td><td>" + strNumOfLoanItem + "</td><td>" + strNumOfReturnItem + "</td></tr>";

                            //arrAssetTypeDesc +=strAssetTypeDesc;
                            //arrAssetItemDesc += strAssetItemDesc;
                            //arrNumOfLoanItem += strNumOfLoanItem;
                            //arrNumOfReturnItem += strNumOfReturnItem;
                        }
                        //this.Arr[e.Row.RowIndex] = strStationEventID + "^" + arrAssetTypeDesc + "^" + arrAssetItemDesc + "^" + arrNumOfLoanItem + "^" + arrNumOfReturnItem;

                        strDifferentByStatusID += "</table>";
                    }

                }
                else if (strEventTypeID == "3")
                {
                    strEventURL = "FireProtection/FireProtectionEntry.aspx?Action=Edit&PageID=OutstandingActivitiesListing&";
                    string strFireSystem = grdActivitiesListing.DataKeys[e.Row.RowIndex]["FireSystem"].ToString();
                    string strFireLinkStatus = grdActivitiesListing.DataKeys[e.Row.RowIndex]["FireLinkStatus"].ToString();
                    string strIsolatedGrp = grdActivitiesListing.DataKeys[e.Row.RowIndex]["IsolatedGrp"].ToString();

                    strDifferentByStatusID += "<table><tr><td>" + GetLabel("SOM_FireProtectionSystem", true) + "</td><td>" + strFireSystem + "</td></tr>";
                    strDifferentByStatusID += "<tr><td>" + GetLabel("SOM_FireLinkStatus", true) + "</td><td>" + strFireLinkStatus + "</td></tr>";
                    strDifferentByStatusID += "<tr><td>" + GetLabel("SOM_FireZoneGroupLoopBeingIsolated", true) + "</td><td>" + strIsolatedGrp + "</td></tr></table>";
                }
                else// if (strEventTypeID == "4")
                {
                    strEventURL = "GeneralEvent/GeneralEventEntry.aspx?PageID=OutstandingActivitiesListing&";
                    string strDescription = grdActivitiesListing.DataKeys[e.Row.RowIndex]["Description"].ToString();
                    string strWorkCategory = grdActivitiesListing.DataKeys[e.Row.RowIndex]["WorkCategory"].ToString();
                    string strWorkSubCategory = grdActivitiesListing.DataKeys[e.Row.RowIndex]["WorkSubCategory"].ToString();

                    //strDifferentByStatusID += "<tr><td>" + GetLabel("SOM_WorkCategory", true) + "</td><td>" + strWorkCategory + "</td></tr>";
                    //strDifferentByStatusID += "<tr><td>" + GetLabel("SOM_WorkSubCategory", true) + "</td><td>" + strWorkSubCategory + "</td></tr>";
                    strDifferentByStatusID += "<table><tr><td>" + GetLabel("SOM_WorkCategory", false) + GetLabel("SOM_SBCOrDBCCase", false) + GetLabel("SOM_WorkSubCategory", true) + "</td><td>" + strWorkCategory + GetLabel("SOM_SBCOrDBCCase", false) + strWorkSubCategory + "</td></tr>";
                    strDifferentByStatusID += "<tr><td>" + GetLabel("COM_Description", true) + "</td><td>" + strDescription + "</td></tr></table>";

                    //delete by gordon 20150721 U138
                    //strDifferentTime = "<table><tr><td>" + GetLabel("SOM_RemindTime", true) + "</td><td>" + strEventRemindTime + "</td></tr></table>";
                }
                string strEventType = grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventType"].ToString();
                string strEventNo = grdActivitiesListing.DataKeys[e.Row.RowIndex]["EventNo"].ToString();
                string strParentStationEventID = grdActivitiesListing.DataKeys[e.Row.RowIndex]["ParentStationEventID"].ToString();
                string strStaffName = grdActivitiesListing.DataKeys[e.Row.RowIndex]["StaffName"].ToString();
                string strDepartmentCompany = grdActivitiesListing.DataKeys[e.Row.RowIndex]["DepartmentCompany"].ToString();
                string strTel = grdActivitiesListing.DataKeys[e.Row.RowIndex]["Tel"].ToString();

                strEventURL = Request.ApplicationPath + "/SOM/" + strEventURL + "StationEventID=" + strStationEventID;
                string strEventStatusIcon = "";
                string strFlagComplete = "<input type=\"checkbox\" onclick=\"HTMLChangeToComplete('" + strEventURL + "&Destroy=TRUE" + "');return false;\" />";
                string strFastCompleteButton = ""; //Add by zengshunbo 2008-12-26

                string strStationEventStatusDesc = "";

                //if (strEventStatusID == "1")
                //if (strEventStatusID == "1" && strEventTypeID.Trim() != "4")//Add by zengshunbo 2009-01-12 actionlog 0886 //comment by jack 20151019 for u245
                if (strEventStatusID == "1")
                {
                    strStationEventStatusDesc = GetLabel("SOM_OS");
                    strEventStatusIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/EventStatus_OS.gif' style='border-width:0px' title='" + strStationEventStatusDesc + "'/>";
                    if (strEventTypeID.Trim() != "4") //add by jack 20151019 for u245 
                    {
                        strFastCompleteButton = "<img src=\"../../Images/SOM/RapidComplete.gif\" class=\"FastCompalete\" " + "title=\"" + GetLabel("SOM_FastComplete", this.LangCode) + "\" onclick=\"HTMLChangeToComplete('" + strEventURL + "&Destroy=TRUE" + "');return false;\" />";//Add by zengshunbo 2008-12-26
                    }
                }
                else if (strEventStatusID == "2")
                {
                    strStationEventStatusDesc = GetLabel("SOM_Completed");
                    strEventStatusIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/EventStatus_COM.gif' style='border-width:0px' title='" + strStationEventStatusDesc + "'/>";
                    strFlagComplete = "<input type='checkbox' disabled checked />";

                    strFastCompleteButton = "<img src=\"../../Images/SOM/RapidComplete.gif\" " + " style=\"display:none;\"  " + " onclick=\"HTMLChangeToComplete('" + strEventURL + "&Destroy=TRUE" + "');return false;\" />";//Add by zengshunbo 2008-12-26
                }
                else if (strEventStatusID == "3")
                {
                    strStationEventStatusDesc = GetLabel("SOM_VoidOperation");
                    strEventStatusIcon = "<img src='" + Request.ApplicationPath + "/Images/SOM/EventStatus_Void.gif' style='border-width:0px' title='" + strStationEventStatusDesc + "'/>";

                    // ------------------- Add by zengshunbo 2008-12-26 ---------------

                    if (strEventStatusID == "3" || strEventTypeID.Trim() == "4")
                    {
                        strFastCompleteButton = "<img src=\"../../Images/SOM/RapidComplete.gif\" " + " style=\"display:none;\"  " + " onclick=\"HTMLChangeToComplete('" + strEventURL + "&Destroy=TRUE" + "');return false;\" />";
                    }
                    else
                    {
                        strFastCompleteButton = "<img src=\"../../Images/SOM/RapidComplete.gif\" class=\"FastCompalete\" " + "title=\"" + GetLabel("SOM_FastComplete", this.LangCode) + " \" onclick=\"HTMLChangeToComplete('" + strEventURL + "&Destroy=TRUE" + "');return false;\" />";
                    }

                    //--------------------- End add by zengshunbo 2008-12-26 ----------
                }

                e.Row.Cells[0].Text = "<table style=\"width:100%;\"><tr><td>" + strHighLightIcon + "</td></tr></table>";
                //e.Row.Cells[1].Text = "<table style=\"width:100%;\"><tr><td nowrap>" + strFlagComplete + "<br>" + GetLabel("SOM_Completed") + "</td></tr></table>"; //huangyao 20081127 modifiy in MTR office
                e.Row.Cells[1].Text = "<table style=\"width:100%;\"><tr><td nowrap>" + strFlagComplete + "</td></tr></table>"; ////huangyao 20081127 modifiy in MTR office
                e.Row.Cells[2].Text = "<table style=\"width:100%;\"><tr><td>" + strEventStatusIcon + "</td></tr></table>";
                e.Row.Cells[3].Text = "<table style=\"width:100%;\"><tr><td>" + strFlagHandoverIcon + "</td></tr></table>";
                e.Row.Cells[4].Text = "<table style=\"width:100%;\"><tr><td nowrap>" + strEventTime + "</td></tr></table>";

                string strCells1 = "<table style=\"\"><tr><td colspan=\"2\"><b>" + strEventType + "</b>";
                string strSpace = this.LangCode == "1" ? " " : "";
                ///update by benson 2015-06-30 begin
                strCells1 += "&nbsp;&nbsp;&nbsp;" + "" + strSpace + GetLabel("SOM_EventNo", true) + "<a class='ShowUnderline' onclick='windowOpen(\"" + strEventURL + " \");' href='javascript:void(0);' >" + strEventNo + "</a>&nbsp;&nbsp;&nbsp;" + "<span class='SOM_EventStatus" + strEventStatusID.ToString() + "'>" + strStationEventStatusDesc + "</span>&nbsp;&nbsp;&nbsp;<span style='padding-right:8px;'>" + strFastCompleteButton + "</span>";//Add by zengshunbo 2008-12-26
                ///update by benson 2015-06-30 end
                if (strParentStationEventID != "0")
                {
                    string arurl = Request.ApplicationPath + "/SOM/AdmissionRegistry/AdmissionRegistryEntry.aspx?StationEventID=" + strParentStationEventID + "&PageID=OutstandingActivitiesListing&";
                    strCells1 += "&nbsp;&nbsp;&nbsp;" + GetLabel("SOM_AdmissionRegistryNo", true)
                                        + "<a class='ShowUnderline' onclick='windowOpen(\"" + arurl + " \");' href='javascript:void(0);' >" + grdActivitiesListing.DataKeys[e.Row.RowIndex]["ParentEventNo"].ToString() + "</a>&nbsp;&nbsp;&nbsp;"
                                        + "<span class='SOM_EventStatus" + grdActivitiesListing.DataKeys[e.Row.RowIndex]["ParentEventStatusID"].ToString() + "'>" + grdActivitiesListing.DataKeys[e.Row.RowIndex]["ParentEventStatus"].ToString() + "</span>"; ;
                }
                //strCells1 += "</tr>";
                strCells1 += "</tr></table>";

                //strCells1 += "<table>";
                //strCells1 += "<tr><td style=\"\">" + GetLabel("COM_StaffName", true) + "</td><td class=\"breakword\" width=\"\">" + strStaffName + "</td></tr>";
                //strCells1 += "<tr><td>" + GetLabel("SOM_DepartmentCompany", true) + "</td><td class=\"breakword\">" + strDepartmentCompany + "</td></tr>";
                //strCells1 += "<tr><td>" + GetLabel("COM_ContactNo", true) + "</td><td class=\"breakword\">" + strTel + "</td></tr>";

                // put in one line: by jkeen,20081216
                strCells1 += "<table>";
                strCells1 += "<tr><td style=\"\">" + GetLabel("COM_StaffName", true) + "</td><td class=\"breakword\" width=\"\">" + strStaffName + "</td>";
                strCells1 += "<td style='width:20px'></td><td>" + GetLabel("SOM_DepartmentCompany", true) + "</td><td class=\"breakword\">" + strDepartmentCompany + "</td>";
                strCells1 += "</tr><tr><td>" + GetLabel("COM_ContactNo", true) + "</td><td class=\"breakword\">" + strTel + "</td></tr>";

                strCells1 += "</table>";        // add by jkeen,20081216

                strCells1 += strDifferentTime;
                strCells1 += strDifferentByStatusID;

                e.Row.Cells[5].Text = strCells1;
            }
        }

        protected void ChangeHightLight(object sender, EventArgs e)
        {
            string value = this.hdnValue.Value;
            string[] strHighLight = value.Split('^');
            if (strHighLight.Length != 2)
            {
                Alert(this.GetMessage("COM_UpdateResultFail"));
                return;
            }
            int intSationEventID = int.Parse(strHighLight[0]);
            int intHighLight = int.Parse(strHighLight[1]);

            MTRC.ODMS.BLL.SOM.Event.StationEvent.UpdateStationEventHighLightBySationEventID(intSationEventID, intHighLight, this.ODMUser.ID);
            BindData(false);
        }

        //protected void ChangeToComplete(object sender, EventArgs e)
        //{

        //    string value = this.hdnValue.Value;
        //    string[] strComplete = value.Split('^');
        //    if (strComplete.Length != 2)
        //    {
        //        Alert(this.GetMessage("COM_UpdateResultFail"));
        //        return;
        //    }
        //    string strEventURL = strComplete[1];
        //    if (strEventURL == "1")
        //    {
        //        strEventURL = "AdmissionRegistry/AdmissionRegistryEntry.aspx?Destroy=TRUE&";                
        //    }
        //    else if (strEventURL == "2")
        //    {
        //        strEventURL = "AssetLoan/AssetLoanEntry.aspx?Destroy=TRUE&";
        //    }
        //    else if (strEventURL == "3")
        //    {
        //        strEventURL = "FireProtection/FireProtectionEntry.aspx?Action=Edit&";
        //    }
        //    else
        //    {
        //        strEventURL = "GeneralEvent/GeneralEventEntry.aspx?";
        //    }

        //    Response.Redirect(APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/" + strEventURL + "StationEventID=" + strComplete[0]);

        //}
        #endregion

        #region Web Form Designer generated code

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.ChangeLanguage += new MTRC.ODMS.Web.BasePage.ChangeLanguageEventHandler(this.ChangeLanguage_Click);
            this.btnSearch.ServerClick += new EventHandler(btnSearch_ServerClick);
            this.btnStationStatus.ServerClick += new EventHandler(btnStationStatus_ServerClick);
            //this.imgbtnReturned.Click += new EventHandler(btnStationStatus_ServerClick);
            //this.imgbtnReturned.Click += new ImageClickEventHandler(imgbtnReturned_Click);
            this.btnExporttoExcel.ServerClick += new EventHandler(btnExporttoExcel_ServerClick);
            // remove by dylan 20150826 for u167 
            //this.btnChangeToNormal.ServerClick += new EventHandler(btnChangeToNormal_ServerClick);
            this.grdActivitiesListing.NeedDataBind += new APJ.Web.UI.WebControls.CommonGridView.NeedDataBindHandler(grdActivitiesListing_NeedDataBind);
        }

        #endregion

        protected void chkSearch_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSearch.Checked)
            {
                this.TimerRefresh.Enabled = true;
            }
            else
            {
                this.TimerRefresh.Enabled = false;
            }
        }

        protected void TimerRefresh_Tick(object sender, EventArgs e)
        {
            btnSearch_ServerClick(null, EventArgs.Empty);
            btnStationStatus_ServerClick(null, EventArgs.Empty);
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            this.btnStationStatus_ServerClick(null, EventArgs.Empty);
        }

        //edit by hjh 20120516 for issue 1531
        private DataSet getData()
        {
            string stationIDs = "";
            SetStationSelectedItem(ref stationIDs, this.ddlStation);
            DateTime dtEstimatedCompletion;
            if (this.chkEstimatedCompletion.Checked)
            {
                dtEstimatedCompletion = this.dtbEstimatedCompletion.GetDateTime();
            }
            else
            {
                dtEstimatedCompletion = DateTime.MinValue;
            }

            int intAndOR = -1;
            string strConditionOne = string.Empty;
            string strConditionTwo = string.Empty;
            string strConditionThree = string.Empty;
            if (chkFreeTextSearch.Checked)
            {
                intAndOR = this.rdoAnd.Checked ? 1 : 0;
                strConditionOne = TxtConditionOne.Text;
                strConditionTwo = TxtConditionTwo.Text;
                strConditionThree = TxtConditionThree.Text;
            }

            bool StatusCom = false;
            bool StatusOS = false;
            bool StatusHandover = false;
            bool StatusVoid = false;
            /*StatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48  */
            bool StatusReturnedItemInOsEvent = false;
            for (int i = 0; i < this.chklShow.Items.Count; i++)
            {
                if (this.chklShow.Items[i].Selected)
                {
                    if (this.chklShow.Items[i].Value == "2")
                    {
                        StatusCom = true;
                    }
                    else if (this.chklShow.Items[i].Value == "1")
                    {
                        StatusOS = true;
                        IsStatusOs = true;
                    }
                    else if (this.chklShow.Items[i].Value == "3")
                    {
                        StatusVoid = true;
                    }

                    else if (this.chklShow.Items[i].Value == "Handover")
                    {
                        StatusHandover = true;
                    }
                    /*Handover Add by Dylan 20150617 for ISSUE U48  */
                    if (cbxReturnItemOs.Checked)
                    {
                        /*StatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48  */
                        StatusReturnedItemInOsEvent = true;
                        IsStatusReturnedItemInOsEvent = true;
                    }
                }
            }

            bool WordCategoryA = false;
            bool WordCategoryL = false;
            bool WordCategoryF = false;
            bool WordCategoryG = false;
            for (int i = 0; i < this.cblWordCategory.Items.Count; i++)
            {
                if (this.cblWordCategory.Items[i].Selected)
                {
                    if (this.cblWordCategory.Items[i].Value == "1")
                    {
                        WordCategoryA = true;
                    }
                    else if (this.cblWordCategory.Items[i].Value == "2")
                    {
                        WordCategoryL = true;
                    }
                    else if (this.cblWordCategory.Items[i].Value == "3")
                    {
                        WordCategoryF = true;
                    }
                    else if (this.cblWordCategory.Items[i].Value == "4")
                    {
                        WordCategoryG = true;
                    }
                }
            }
            DataSet dsSearchResult = MTRC.ODMS.BLL.SOM.Event.StationActivitiesListing.GetActivitiesListingEnquiry(this.LangCode,
                                                                                              this.ODMUser.LocationID, stationIDs,
                                                                                              this.dtbFromDate.GetDateTime(),
                                                                                              this.dtbToDate.GetDateTime(),
                                                                                               StatusCom, StatusOS, StatusHandover, StatusVoid,
                                                                                              WordCategoryA, WordCategoryL, WordCategoryF, WordCategoryG,
                                                                                              intAndOR,
                                                                                              strConditionOne,
                                                                                              strConditionTwo,
                                                                                              strConditionThree,
                                                                                              dtEstimatedCompletion);
            return dsSearchResult;
        }

        #region   added by Nathan 2015-08-15


        /// <summary>
        /// Encryption
        /// </summary>
        public void TxtJM()
        {
            if (TxtConditionOne.Text.Trim().Length > 0)
            {
                string str = TxtConditionOne.Text;

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionOne->Before Encrypt:" + str, 4, ODMUser.ID, ODMUser.UserGroupName);

                string strJM = APJ.Util.Utility.AESEncrypt(str);

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionOne->After Encrypt:" + strJM, 4, ODMUser.ID, ODMUser.UserGroupName);

                TextOne.Text = strJM;
            }
            else
            {
                TextOne.Text = "";
            }
            if (TxtConditionTwo.Text.Trim().Length > 0)
            {
                string str = TxtConditionTwo.Text;

                //add by gordon 20160216 ISU51
               // BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionTwo->Before Encrypt:" + str, 4, ODMUser.ID, ODMUser.UserGroupName);

                string strJM = APJ.Util.Utility.AESEncrypt(str);

                //add by gordon 20160216 ISU51
               // BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionTwo->After Encrypt:" + strJM, 4, ODMUser.ID, ODMUser.UserGroupName);

                TextTwo.Text = strJM;
            }
            else
            {
                TextTwo.Text = "";
            }
            if (TxtConditionThree.Text.Trim().Length > 0)
            {
                string str = TxtConditionThree.Text;

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionThree->Before Encrypt:" + str, 4, ODMUser.ID, ODMUser.UserGroupName);

                string strJM = APJ.Util.Utility.AESEncrypt(str);

                //add by gordon 20160216 ISU51
               // BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionThree->After Encrypt:" + strJM, 4, ODMUser.ID, ODMUser.UserGroupName);

                TextThree.Text = strJM;
            }
            else
            {
                TextThree.Text = "";
            }

        }

        /// <summary>
        /// Decryption
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public void JMText()
        {
            if (TextOne.Text.Trim().Length > 0 && TxtConditionOne.Text.Trim().Length <= 0)
            {
                string str = TextOne.Text;

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionOne->Before Decrypt:" + str, 4, ODMUser.ID, ODMUser.UserGroupName);

                TxtConditionOne.Text = APJ.Util.Utility.AESDecrypt(str);

                //add by gordon 20160216 ISU51
               // BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionOne->After Decrypt:" + TxtConditionOne.Text, 4, ODMUser.ID, ODMUser.UserGroupName);

            }
            if (TextTwo.Text.Trim().Length > 0 && TxtConditionTwo.Text.Trim().Length <= 0)
            {
                string str = TextTwo.Text;

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionTwo->Before Decrypt:" + str, 4, ODMUser.ID, ODMUser.UserGroupName);

                TxtConditionTwo.Text = APJ.Util.Utility.AESDecrypt(str);

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionTwo->After Decrypt:" + TxtConditionTwo.Text, 4, ODMUser.ID, ODMUser.UserGroupName);

            }
            if (TextThree.Text.Trim().Length > 0 && TxtConditionThree.Text.Trim().Length <= 0)
            {
                string str = TextThree.Text;

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionThree->Before Decrypt:" + str, 4, ODMUser.ID, ODMUser.UserGroupName);

                TxtConditionThree.Text = APJ.Util.Utility.AESDecrypt(str);

                //add by gordon 20160216 ISU51
                //BLL.SOM.Log.Logger("ActivitiesListing->TxtConditionThree->After Decrypt:" + TxtConditionThree.Text, 4, ODMUser.ID, ODMUser.UserGroupName);
            }
        }

        protected void chkFreeTextSearch_CheckedChanged(object sender, EventArgs e)
        {
            if (chkFreeTextSearch.Checked)
            {
                TxtConditionOne.Enabled = true;
                TxtConditionTwo.Enabled = true;
                TxtConditionThree.Enabled = true;
                rdoAnd.Enabled = true;
                rdoOr.Enabled = true;
                rdoAnd.Checked = true;
            }
            else
            {
                TxtConditionOne.Enabled = false;
                TxtConditionTwo.Enabled = false;
                TxtConditionThree.Enabled = false;
                rdoAnd.Enabled = false;
                rdoOr.Enabled = false;
                rdoAnd.Checked = true;

                TxtConditionOne.Text = "";
                TxtConditionTwo.Text = "";
                TxtConditionThree.Text = "";
                TextOne.Text = "";
                TextTwo.Text = "";
                TextThree.Text = "";
            }
            if (TextRadio.Text.Trim().Length > 0)
            {
                if (TextRadio.Text.Trim() == "2")
                {
                    rdoAnd.Checked = false;
                    rdoOr.Checked = true;
                }
                else
                {
                    rdoAnd.Checked = true;
                    rdoOr.Checked = false;
                }
            }

        }
        #endregion  added by Nathan 2015-08-15

        /// <summary>
        /// add by jack 20151202 for using session store enquiry condition
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSetSession_Click(object sender, EventArgs e)
        {
            this.RemoveCommonSession();
            string Url = this.HiddenFieldUrl.Value;
            Session["Common_Station"] = this.ddlStation.SelectedValue.ToString();
            Session["Common_DateFrom"] = this.dtbFromDate.Text.ToString();
            Session["Common_DateTo"] = this.dtbToDate.Text.ToString();
            Session["Common_ShowList"] = this.GetCheckboxListValue(this.chklShow);
            Session["OutstandingActivity_Category"] = this.GetCheckboxListValue(this.cblWordCategory);
            Session["OutstandingActivity_Search"] = this.chkSearch.Checked;
            Session["OutstandingActivity_ReturnItemOs"] = this.cbxReturnItemOs.Checked;
            Session["Common_FreeTextSearch"] = this.chkFreeTextSearch.Checked;
            Session["Common_ConditionOne"] = this.TextOne.Text.ToString();
            Session["Common_ConditionTwo"] = this.TextTwo.Text.ToString();
            Session["Common_ConditionThree"] = this.TextThree.Text.ToString();
            Session["Common_RdoAnd"] = this.rdoAnd.Checked;
            Session["Common_RdoOr"] = this.rdoOr.Checked;
            Response.Redirect(Url + "&isBack=1");
        }
    }
}
